<?php
session_start();
include "config.php";
if (isset($_SESSION['selco']))
{
# üye
$uyeDetay = DB::getRow("SELECT * FROM uyeler WHERE email = ?", array($_SESSION['selco']));

# sayfalama
define('_go', $_GET['go']);

function farkbul($tarih1,$tarih2,$isaret)
{
    list($g1,$a1,$y1) = explode($isaret,$tarih1);
    list($g2,$a2,$y2) = explode($isaret,$tarih2);
    $tms1 = mktime(0,0,0,$a1,$g1,$y1);
    $tms2 = mktime(0,0,0,$a2,$g2,$y2);
    if($tms1>$tms2)
    {
        $fark = $tms1-$tms2;
    }
    elseif($tms2>$tms1)
    {
        $fark = $tms2-$tms1;
    }
    elseif($tms1==$tms2)
    {
        $fark = 0;
    }
    return round($fark/86400);
}

    $simdi = date("d-m-Y");
    $bitis = $uyeDetay->bitis;
    $bitis_ajax = strtotime($uyeDetay->bitis);
    $ajax_zaman = date("F j, Y, H:i:s", $bitis_ajax);

    $gun = farkbul($bitis,$simdi,'-');

    if ( $gun == 0 ){
        DB::exec("UPDATE facebook SET durum = '1' WHERE uyeID = ?", array($uyeDetay->id));
        DB::exec("UPDATE askfm SET durum = '1' WHERE uyeID = ?", array($uyeDetay->id));
        DB::exec("UPDATE twitter SET durum = '1' WHERE uyeID = ?", array($uyeDetay->id));
        DB::query("UPDATE uyeler SET sayfa = '0', abone = '0', durum = '0', liste = '0', twitter = '0', askfm = '0' WHERE id = ?", array($uyeDetay->id));
    }

?>
<!doctype html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title><?php echo $siteAyarlari->title; ?></title>
  <link rel="shortcut icon" href="favicon.gif">
  <!---CSS Files-->
  <link rel="stylesheet" href="css/master.css">
  <link rel="stylesheet" href="css/tables.css">
  <!---jQuery Files-->
  <script src="js/jquery-1.7.1.min.js"></script>
  <script src="js/jquery-ui-1.8.17.min.js"></script>
  <script src="js/styler.js"></script>
  <script src="js/jquery.tipTip.js"></script>
  <script src="js/colorpicker.js"></script>
  <script src="js/sticky.full.js"></script>
  <script src="js/global.js"></script>
  <script src="js/flot/jquery.flot.min.js"></script>
  <script src="js/flot/jquery.flot.resize.min.js"></script>
  <script src="js/jquery.dataTables.min.js"></script>
  <!---Fonts-->
  <link href='http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
  <link href='http://fonts.googleapis.com/css?family=Ubuntu:500' rel='stylesheet' type='text/css'>
  <!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
  <!--[if lte IE 8]>
  <script language="javascript" type="text/javascript" src="js/flot/excanvas.min.js"></script>
  <![endif]-->
  <script src="js/jquery.countdown.js"></script>
  <script type="text/javascript">
    $(function () {
        var austDay = new Date("<?php echo $ajax_zaman; ?>");
        $('#usr-notif').countdown({until: austDay, layout: '{dn} Gün {hn} Saat {mn} Dakika {sn} Saniye'});
        $('#year').text(austDay.getFullYear());
    });
  </script>
</head>
<body>

  <!--- HEADER -->

	<div class="header">
   <a href="index.php"><img src="img/logo.png" alt="Logo" /></a>
  </div>

  <div class="top-bar">
      <ul id="nav">
        <li id="user-panel">
          <img src="img/nav/usr-avatar.jpg" id="usr-avatar" alt="" />
          <div id="usr-info">
            <p id="usr-name"><?php echo $uyeDetay->isim; ?></p>
            <p id="usr-notif"></p>
              <p></p>
            <p>
                <a href="?go=profil">Profilim</a><a href="?go=cikis">Cikis Yap</a>
            </p>
          </div>
        </li>
          <?php
          ( _go == '' ) ? $anasayfa = '-active' : $anasayfa = NULL;
          ( _go == 'facebook' ) ? $facebook = '-active' : $facebook = NULL;
          ( _go == 'twitter' ) ? $twitter = '-active' : $twitter = NULL;
          ( _go == 'askfm' ) ? $askfm = '-active' : $askfm = NULL;
          ( _go == 'odeme' ) ? $odeme = '-active' : $odeme = NULL;
          ( _go == 'ticket' OR _go == 'ticketDetay' ) ? $destek = '-active' : $destek = NULL;
          ?>
        <li>
        <ul id="top-nav">
         <li class="nav-item">
           <a href="index.php"><img src="img/nav/dash<?php echo $anasayfa; ?>.png" alt="" /><p>Anasayfa</p></a>
         </li>
         <li class="nav-item">
           <a href="?go=facebook"><img src="img/nav/grid<?php echo $facebook; ?>.png" alt="" /><p>Facebook</p></a>
         </li>
         <li class="nav-item">
           <a href="?go=twitter"><img src="img/nav/grid<?php echo $twitter; ?>.png" alt="" /><p>Twitter</p></a>
         </li>
         <li class="nav-item">
           <a href="?go=askfm"><img src="img/nav/grid<?php echo $askfm; ?>.png" alt="" /><p>AskFM</p></a>
         </li>
         <li class="nav-item">
           <a href="?go=odeme"><img src="img/nav/flm<?php echo $odeme; ?>.png" alt="" /><p>Ödemeler</p></a>
         </li>
         <li class="nav-item">
           <a href="?go=ticket"><img src="img/nav/typ<?php echo $destek; ?>.png" alt="" /><p>Ticket</p></a>
         </li>
         <?php if ( $uyeDetay->admin == 1 ){ ?>
         <li class="nav-item">
             <a href="admin.php"><img src="img/nav/icn.png" alt="" /><p>Admin Paneli</p></a>
         </li>
         <?php } ?>
       </ul>
      </li>
     </ul>
  </div>

  <!--- CONTENT AREA -->

  <div class="content container_12">

      <?php
    # Silme Sayfa
    if ( _go == 'sil' )
    {
        $id = intval($_GET['id']);
        $type = $_GET['type'];
        if ($type == 'facebook'){
            $sil =  DB::exec("DELETE FROM facebook WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
            if($sil) echo '<script>location = "?go=facebook";</script>';
        } else if ($type == 'twitter'){
            $sil =  DB::exec("DELETE FROM twitter WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
            if($sil) echo '<script>location = "?go=twitter";</script>';
        } else if ($type == 'askfm'){
            $sil =  DB::exec("DELETE FROM askfm WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
            if($sil) echo '<script>location = "?go=askfm";</script>';
        } else if ($type == 'ticket'){
            $sil =  DB::exec("DELETE FROM ticket WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
            if($sil) echo '<script>location = "?go=ticket";</script>';
        }else if ($type == 'odeme'){
            $odemeDetay = DB::getRow("SELECT * FROM odemeler WHERE id = ?", array($id));
            if ( $odemeDetay->durum == 0 ){
                $sil =  DB::exec("DELETE FROM odemeler WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
                if($sil) echo '<script>location = "?go=odeme";</script>';
            } else {
                echo '<script>location = "index.php";</script>';
            }
        }
    }

  # Kapat Sayfa
  if ( _go == 'kapat' )
  {
      $id = intval($_GET['id']);
      $type = $_GET['type'];
      if ($type == 'ticket'){
          $kapat =  DB::exec("UPDATE ticket SET durum = '1' WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
          if($kapat) echo '<script>location = "?go=ticket";</script>';
      }
  }

      # Cikis Sayfa
      if ( _go == 'cikis' )
      {
          session_destroy();
          echo '<script>location = "index.php";</script>';
      }

      #Anasayfa
      if ( _go == '' )
      {
      ?>

      <div class="box grid_12">
        <div class="box-head"><h2>Bilgilendirme & Duyurular</h2></div>
        <div class="box-content">
          <p>
              <?php echo $siteAyarlari->duyurular; ?>
          </p>
        </div>
      </div>

      <?php
      }

      # facebook
      if( _go == 'facebook' )
      {
      ?>
          <div class="box grid_12">
              <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
                  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Facebook</a></li>
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-2">+ Yeni Ekle</a></li>
                  </ul>
                  <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
                  <div class="table-toolbar"></div>
                  <table class="display" id="selcoTablo">
                  <thead>
                  <tr>
                      <th><center>-</center></th>
                      <th>Facebook</th>
                      <th>Tür</th>
                      <th>Baslangic</th>
                      <th>Miktar</th>
                      <th>Bitis</th>
                      <th>Status</th>
                      <th><center>-</center></th>
                  </tr>
                  </thead>
                  <tbody>
                  <?php
                  $i = 1;
                  $facebook = DB::query("SELECT * FROM facebook WHERE uyeID = '$uyeDetay->id' ORDER BY id DESC");
                  foreach ($facebook as $key)
                  {
                  ?>
                  <tr class="odd">
                      <td class="center"><?php echo $i; ?></td>
                      <td class="center"><a href="<?php echo $key->fUrl; ?>" target="_blank" class="tab"><?php echo ucfirst($key->fIsim); ?></a></td>
                      <td class="center"><?php echo ucfirst($key->tur); ?></td>
                      <td class="center"><?php echo $key->baslangic; ?> adet</td>
                      <td class="center"> <?php echo $key->istekLimit; ?> adet</td>
                      <td class="center"> <?php echo ($key->tur == 'liste') ? '0' : $key->baslangic + $key->istekLimit; ?> adet</td>
                      <td class="center"><?php ($key->durum == 0) ? print '<center><span style="color: #ff4330">Islem Yapiliyor</span></center>' : print '<center><span style="color: #12970f">Tamamlandi</span></center>'; ?></td>
                      <td class="center">
                          <center>
                          <ul class="icons">
                              </a><li class="fugue-2 cross-button" onclick="window.location='?go=sil&id=<?php echo $key->id; ?>&type=facebook';" style="cursor: pointer" title="Islemi Durdur"></li>
                          </ul>
                          </center>
                      </td>
                  </tr>
                  <?php
                  $i++;
                  }
                  ?>
                  </tbody>
                  </table>
                  </div>
                  <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="font-size: 12px">
                      <div id="islemSonuc"></div>
                      <form id="sForm" action="" onsubmit="return false">
                      <div class="form-row">
                          <p class="form-label" class="grid_4">Islem Türü</p>
                            <div class="form-item">
                              <select class="grid_4" name="tur">
                                  <option value="sayfa">Sayfa</option>
                                  <option value="abone">Abone</option>
                                  <option value="liste">Liste</option>
                                  <option value="durum">Durum Begeni</option>
                              </select>
                            </div>
                      </div>
                      <div class="form-row">
                          <p class="form-label">Facebook Url</p>
                          <div class="form-item"><input type="text" class="grid_6" name="url"></div>

                          <div class="form-row">
                              <p class="form-label">Miktar</p>
                              <div class="form-item"><input type="text" class="grid_1" name="miktar"></div>
                          </div>
                      <div class="form-row">
                          <p class="form-label"></p>
                          <div class="form-item"><input type="button" class="button big black grid_1" value="Ekle" id="fEkle"></div>
                      </div>
                      </form>
                  </div>
              </div>
          </div>
      <?php
      }

      # twitter
      if( _go == 'twitter' )
      {
          ?>
          <div class="box grid_12">
              <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
                  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Twitter</a></li>
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-2">+ Yeni Ekle</a></li>
                  </ul>
                  <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
                      <div class="table-toolbar"></div>
                      <table class="display" id="selcoTablo">
                          <thead>
                          <tr>
                              <th><center>-</center></th>
                              <th>Twitter</th>
                              <th>Tür</th>
                              <th>Baslangic</th>
                              <th>Miktar</th>
                              <th>Bitis</th>
                              <th>Status</th>
                              <th><center>-</center></th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php
                          $i = 1;
                          $twitter = DB::query("SELECT * FROM twitter WHERE uyeID = '$uyeDetay->id' ORDER BY id DESC");
                          foreach ($twitter as $key)
                          {
                              ?>
                              <tr class="odd">
                                  <td class="center"><?php echo $i; ?></td>
                                  <td class="center"><a href="https://twitter.com/<?php echo ($key->tur == 'takipci') ? $key->tUsername : "$key->tUsername/status/$key->tID"; ?>" target="_blank" class="tab"><?php echo ($key->tur == 'takipci') ? $key->tUsername : $key->tID; ?></a></td>
                                  <td class="center"><?php echo ucfirst($key->tur); ?></td>
                                  <td class="center"><?php echo $key->baslangic; ?> adet</td>
                                  <td class="center"> <?php echo $key->istekLimit; ?> adet</td>
                                  <td class="center"> <?php echo $key->baslangic + $key->istekLimit; ?> adet</td>
                                  <td class="center"><?php ($key->durum == 0) ? print '<center><span style="color: #ff4330">Islem Yapiliyor</span></center>' : print '<center><span style="color: #12970f">Tamamlandi</span></center>'; ?></td>
                                  <td class="center">
                                      <center>
                                          <ul class="icons">
                                              </a><li class="fugue-2 cross-button" onclick="window.location='?go=sil&id=<?php echo $key->id; ?>&type=twitter';" style="cursor: pointer" title="Islemi Durdur"></li>
                                          </ul>
                                      </center>
                                  </td>
                              </tr>
                              <?php
                              $i++;
                          }
                          ?>
                          </tbody>
                      </table>
                  </div>
                  <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="font-size: 12px">
                      <div id="islemSonuc"></div>
                      <form id="sForm" action="" onsubmit="return false">
                          <div class="form-row">
                              <p class="form-label" class="grid_4">Islem Türü</p>
                              <div class="form-item">
                                  <select class="grid_4" name="tur">
                                      <option value="takipci">Takipci</option>
                                      <option value="retweet">Retweet</option>
                                      <option value="favori">Favori</option>
                                  </select>
                              </div>
                          </div>
                          <div class="form-row">
                              <p class="form-label">Twitter Url</p>
                              <div class="form-item"><input type="text" class="grid_6" name="url"></div>

                              <div class="form-row">
                                  <p class="form-label">Miktar</p>
                                  <div class="form-item"><input type="text" class="grid_1" name="miktar"></div>
                              </div>
                              <div class="form-row">
                                  <p class="form-label"></p>
                                  <div class="form-item"><input type="button" class="button big black grid_1" value="Ekle" id="tEkle"></div>
                              </div>
                      </form>
                  </div>
              </div>
          </div>
      <?php
      }

      # Askfm
      if( _go == 'askfm' )
      {
          ?>
          <div class="box grid_12">
              <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
                  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">AskFM</a></li>
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-2">+ Yeni Ekle</a></li>
                  </ul>
                  <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
                      <div class="table-toolbar"></div>
                      <table class="display" id="selcoTablo">
                          <thead>
                          <tr>
                              <th><center>-</center></th>
                              <th>AskFm</th>
                              <th>Baslangic</th>
                              <th>Miktar</th>
                              <th>Bitis</th>
                              <th>Status</th>
                              <th><center>-</center></th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php
                          $i = 1;
                          $askfm = DB::query("SELECT * FROM askfm WHERE uyeID = '$uyeDetay->id' ORDER BY id DESC");
                          foreach ($askfm as $key)
                          {
                              ?>
                              <tr class="odd">
                                  <td class="center"><?php echo $i; ?></td>
                                  <td class="center"><a href="http://ask.fm/<?php echo $key->aUsername; ?>/answer/<?php echo $key->aID; ?>" target="_blank" class="tab">@<?php echo $key->aUsername; ?>-><?php echo $key->aID; ?></a></td>
                                  <td class="center"><?php echo $key->baslangic; ?> adet</td>
                                  <td class="center"> <?php echo $key->istekLimit; ?> adet</td>
                                  <td class="center"> <?php echo $key->baslangic + $key->istekLimit; ?> adet</td>
                                  <td class="center"><?php ($key->durum == 0) ? print '<center><span style="color: #ff4330">Islem Yapiliyor</span></center>' : print '<center><span style="color: #12970f">Tamamlandi</span></center>'; ?></td>
                                  <td class="center">
                                      <center>
                                          <ul class="icons">
                                              </a><li class="fugue-2 cross-button" onclick="window.location='?go=sil&id=<?php echo $key->id; ?>&type=askfm';" style="cursor: pointer" title="Islemi Durdur"></li>
                                          </ul>
                                      </center>
                                  </td>
                              </tr>
                              <?php
                              $i++;
                          }
                          ?>
                          </tbody>
                      </table>
                  </div>
                  <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="font-size: 12px">
                      <div id="islemSonuc"></div>
                      <form id="sForm" action="" onsubmit="return false">
                          <div class="form-row">
                              <p class="form-label">Askfm Soru Url</p>
                              <div class="form-item"><input type="text" class="grid_6" name="url"></div>

                              <div class="form-row">
                                  <p class="form-label">Miktar</p>
                                  <div class="form-item"><input type="text" class="grid_1" name="miktar"></div>
                              </div>
                              <div class="form-row">
                                  <p class="form-label"></p>
                                  <div class="form-item"><input type="button" class="button big black grid_1" value="Ekle" id="aEkle"></div>
                              </div>
                      </form>
                  </div>
              </div>
          </div>
      <?php
      }

      # Ödeme
      if( _go == 'odeme' )
      {
          ?>
          <div class="box grid_12">
              <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
                  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Ödeme Gecmisi</a></li>
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-2">+ Yeni Ekle</a></li>
                  </ul>
                  <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
                      <div class="table-toolbar"></div>
                      <table class="display" id="selcoTablo">
                          <thead>
                          <tr>
                              <th><center>-</center></th>
                              <th>Tutar</th>
                              <th>Ref. Numara</th>
                              <th>Aciklama</th>
                              <th>Tarih</th>
                              <th>Status</th>
                              <th><center>-</center></th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php
                          $i = 1;
                          $odemeler = DB::query("SELECT * FROM odemeler WHERE uyeID = '$uyeDetay->id' ORDER BY id DESC");
                          foreach ($odemeler as $key)
                          {
                              ?>
                              <tr class="odd">
                                  <td class="center"><?php echo $i; ?></td>
                                  <td class="center"><?php echo $key->tutar; ?> TL</td>
                                  <td class="center"><?php echo $key->refNumara; ?></td>
                                  <td class="center"> <?php echo $key->aciklama; ?></td>
                                  <td class="center"><?php echo _date(date("j M Y D H:i", $key->tarih)); ?></td>
                                  <td class="center"><?php ($key->durum == 0) ? print '<center><span style="color: #ff4330">Islem Yapiliyor</span></center>' : print '<center><span style="color: #12970f">Tamamlandi</span></center>'; ?></td>
                                  <td class="center">
                                      <center>
                                          <ul class="icons">
                                            <?php if($key->durum == 0){ ?>
                                              <li class="fugue-2 cross-button" onclick="window.location='?go=sil&id=<?php echo $key->id; ?>&type=odeme';" style="cursor: pointer" title="Islemi Durdur"></li>
                                            <?php } else { ?>
                                                <center>-</center>
                                            <?php } ?>
                                          </ul>
                                      </center>
                                  </td>
                              </tr>
                              <?php
                              $i++;
                          }
                          ?>
                          </tbody>
                      </table>
                  </div>
                  <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="font-size: 12px">
                      <div id="islemSonuc"></div>
                      <form id="sForm" action="" onsubmit="return false">
                              <div class="form-row">
                                  <p class="form-label">Süre</p>
                                  <div class="form-item"><input type="text" class="grid_2" value="1" name="sure"></div>
                              </div>
                              <div class="form-row">
                                  <p class="form-label" class="grid_4">Bayilik Tür</p>
                                  <div class="form-item">
                                      <select class="grid_2" name="tur">
                                          <option value="gunluk">Günlük</option>
                                          <option value="haftalik">Haftalik</option>
                                          <option value="aylik">Aylik</option>
                                      </select>
                                  </div>
                              </div>
                              <div class="form-row">
                                  <p class="form-label"></p>
                                  <div class="form-item"><input type="button" class="button big black grid_1" value="Öde" id="odeme"></div>
                              </div>
                      </form>
                  </div>
              </div>
          </div>
      <?php
      }

      # Profil
      if ( _go == 'profil' )
      {

      if ( $_POST )
      {
          $sifre = md5(sha1(trim($_POST['sifre'])));
          $sifre2 = md5(sha1(trim($_POST['sifre2'])));
          $suankisifre = md5(sha1(trim($_POST['suankisifre'])));

          if ( $suankisifre == $uyeDetay->sifre )
          {
              if ( $sifre == $sifre2 )
              {
                  $guncelle = DB::query("UPDATE uyeler SET sifre = '$sifre' WHERE id = '$uyeDetay->id'");
                  echo $guncelle ? '<script>location="index.php";</script>' : '<script>alert("Hata Olustu");</script>';
              } else {
                  echo '<script>alert("Sifreler uyusmuyor");</script>';
              }
          } else {
              echo '<script>alert("Suanki sifre yanlis");</script>';
          }
      }
      ?>

      <div class="box grid_12">
          <div class="box-head"><h2><?php echo $uyeDetay->isim; ?></h2></div>
          <div class="box-content">
              <p>
              <form action="" method="post">
                  <div class="form-row">
                      <p class="form-label">Yeni Sifre</p>
                      <div class="form-item"><input type="password" class="grid_4" name="sifre" value=""></div>
                  </div>
                  <div class="form-row">
                      <p class="form-label">Yeni Sifre(tekrar)</p>
                      <div class="form-item"><input type="password" class="grid_4" name="sifre2" value=""></div>
                  </div>

                  <div class="form-row">
                      <p class="form-label">Suanki Sifre</p>
                      <div class="form-item"><input type="password" class="grid_4" name="suankisifre" value=""></div>
                  </div>
                  <div class="form-row">
                      <p class="form-label"></p>
                      <div class="form-item"><input type="submit" class="button big black grid_2" value="Güncelle"></div>
                  </div>

          </div>
          </form>
          </p>
      </div>
  </div>

  <?php
  }

      # Ticket
      if( _go == 'ticket' )
      {
          ?>
          <div class="box grid_12">
              <div id="tabs" class="ui-tabs ui-widget ui-widget-content ui-corner-all">
                  <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-1">Ticket</a></li>
                      <li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabs-2">+ Yeni Ekle</a></li>
                  </ul>
                  <div id="tabs-1" class="ui-tabs-panel ui-widget-content ui-corner-bottom">
                      <div class="table-toolbar"></div>
                      <table class="display" id="selcoTablo">
                          <thead>
                          <tr>
                              <th><center>-</center></th>
                              <th>Konu</th>
                              <th>Tarih</th>
                              <th>Status</th>
                              <th><center>-</center></th>
                          </tr>
                          </thead>
                          <tbody>
                          <?php
                          $i = 1;
                          $destekler = DB::query("SELECT * FROM ticket WHERE uyeID = '$uyeDetay->id'  ORDER BY id DESC");
                          foreach ($destekler as $destek)
                          {
                              if ($destek->durum == 0) {
                                  $ticketSonCevap = DB::getRow("SELECT * FROM ticketcevaplar WHERE ticketID = '$destek->id' ORDER BY id DESC");
                                  if (!$ticketSonCevap){
                                      $durum = '<span style="color: #8b0000">Beklemede</span>';
                                  } else {
                                      if ($ticketSonCevap->cevapYoneticiID){
                                          $durum = '<span style="color: #058b00">Cevaplandi</span>';
                                      } elseif ($ticketSonCevap->cevapUyeID){
                                          $durum = '<span style="color: #8B0000">Müsteri Yanitladi</span>';
                                      } else {
                                          $durum = '<span style="color: #8b0000">Beklemede</span>';
                                      }
                                  }
                              } else {
                                  $durum = '<span style="color: #18568b">Sonlandirildi</span>';
                              }

                              $destek->konu = str_replace("\\", "", $destek->konu);
                              $destek->konu = str_replace("'", "", $destek->konu);
                          ?>
                              <tr class="odd">
                                  <td class="center"><?php echo $i; ?></td>
                                  <td><a href="?go=ticketDetay&id=<?php echo $destek->id; ?>" class="tab"><small><?php echo substr($destek->konu, 0, 90); ?></small></a></td>
                                  <td class="center"><?php echo _date(date("j M Y D H:i", $destek->tarih)); ?></td>
                                  <td class="center"><?php echo $durum; ?></td>
                                  <td class="center">
                                      <center>
                                          <?php if($destek->durum == 0){ ?>
                                          <li class="silk tick" onclick="window.location='?go=kapat&id=<?php echo $destek->id; ?>&type=ticket';" style="list-style:none; cursor: pointer" title="Ticket Kapat"></li><?php } ?>
                                          <li class="fugue-2 cross-button" onclick="window.location='?go=sil&id=<?php echo $destek->id; ?>&type=ticket';" style="list-style:none; cursor: pointer" title="Ticket Sil"></li>
                                      </center>
                                  </td>
                              </tr>
                              <?php
                              $i++;
                          }
                          ?>
                          </tbody>
                      </table>
                  </div>
                  <div id="tabs-2" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="font-size: 12px">
                      <div id="islemSonuc"></div>
                      <form id="sForm" action="" onsubmit="return false">
                          <div class="form-row">
                              <p class="form-label">Konu</p>
                              <div class="form-item"><input type="text" class="grid_4"name="konu"></div>
                          </div>
                          <div class="form-row">
                              <p class="form-label">Icerik</p>
                              <div class="form-item"><textarea class="grid_4"name="icerik" style="height: 100px; border: 1px solid #dddddd"></textarea></div>
                          </div>
                          <div class="form-row">
                              <p class="form-label"></p>
                              <div class="form-item"><input type="button" class="button big black grid_1" value="Ekle" id="ticket"></div>
                          </div>
                      </form>
                  </div>
              </div>
          </div>
      <?php
      }

      # Ticket Detay
      if( _go == 'ticketDetay' )
      {
          $id = intval($_GET['id']);
          $ticketDetay = DB::getRow("SELECT * FROM ticket WHERE id = ? and uyeID = ?", array($id, $uyeDetay->id));
          if ($ticketDetay->id){
      ?>
          <div class="box grid_12">
              <div class="box-head"><h2><?php echo $ticketDetay->konu; ?></h2></div>
              <div class="box-content textsh">
                  <div style="border-radius: 10px; border: 1px solid #a0a0a0; margin-bottom: 20px">
                      <div style="border-radius: 10px; background-color: #dddddd; font-size: 12px; padding: 10px">
                          <p style="float: right"><?php echo _date(date("j M Y D", $ticketDetay->tarih)); ?></p>
                          <p style="font-weight: bolder"><?php echo $uyeDetay->isim; ?></p>
                          <p style="clear: both">Müsteri</p>
                      </div>
                      <div style="font-size: 12px; padding: 15px">
                          <p>
                              <?php
                              $ticketDetay->icerik = str_replace("\\", "", $ticketDetay->icerik);
                              $ticketDetay->icerik = str_replace("'", "", $ticketDetay->icerik);
                              $ticketDetay->icerik = str_replace("\n", "<br>", $ticketDetay->icerik);
                              echo $ticketDetay->icerik;
                              ?>
                          </p>
                      </div>
                  </div>

                  <?php
                  $ticketCevapToplam = DB::getVar("SELECT count(id) FROM ticketcevaplar WHERE ticketID = '$ticketDetay->id'");
                  if ($ticketCevapToplam > 0){

                      $ticketCevaplar = DB::query("SELECT * FROM ticketcevaplar WHERE ticketID = '$ticketDetay->id' ORDER BY id ASC");
                      foreach($ticketCevaplar as $ticketCevap){

                          if ($ticketCevap->cevapUyeID != 0)
                          {
                              $ticketCevapUyeDetay = DB::getRow("SELECT * FROM uyeler WHERE id = '$ticketCevap->cevapUyeID'");
                              $statu = 'Müsteri';
                          }elseif($ticketCevap->cevapYoneticiID != 0){
                              $ticketCevapUyeDetay = DB::getRow("SELECT * FROM uyeler WHERE id = '$ticketCevap->cevapYoneticiID'");
                              $statu = '<span style="color: darkred">Yetkili</span>';
                          }
                  ?>

                  <div style="border-radius: 10px; border: 1px solid #a0a0a0; margin-bottom: 20px">
                      <div style="border-radius: 10px; background-color: #dddddd; font-size: 12px; padding: 10px">
                          <p style="float: right"><?php echo _date(date("j M Y D H:i", $ticketCevap->tarih)); ?></p>
                          <p style="font-weight: bolder"><?php echo $ticketCevapUyeDetay->isim; ?></p>
                          <p style="clear: both"><?php echo $statu; ?></p>
                      </div>
                      <div style="font-size: 12px; padding: 15px">
                          <p>
                              <?php
                              $ticketCevap->icerik = str_replace("\\", "", $ticketCevap->icerik);
                              $ticketCevap->icerik = str_replace("'", "", $ticketCevap->icerik);
                              $ticketCevap->icerik = str_replace("\n", "<br>", $ticketCevap->icerik);
                              echo $ticketCevap->icerik;
                              ?>
                          </p>
                      </div>
                  </div>

                  <?php
                      }
                  }
                  ?>

              </div>
          </div>
          <?php
          if ($ticketDetay->durum == 0)
          {
              $icerik = addslashes(htmlspecialchars(trim($_POST['icerik'])));
              if ( $icerik )
              {
                  $ekle = DB::insert(
                      'INSERT INTO ticketcevaplar (ticketID, cevapUyeID, icerik, tarih) VALUES (?, ?, ?, ?)',
                      array($_GET['id'], $uyeDetay->id, $icerik, time())
                  );

                  if ($ekle)
                  {
                      echo '<script>location="?go=ticketDetay&id='.$_GET['id'].'";</script>';
                  } else {
                      echo '<script>alert("HATA");</script>';
                  }
              }
          ?>
          <div class="box grid_12">
              <div class="box-head"><h2>Cevap Yaz</h2></div>
              <div class="box-content textsh">
                  <form class="form-horizontal" action="" method="post">
                  <div class="form-row">
                      <div class="form-item">
                          <textarea id="form-field-23" class="grid_12" name="icerik" style="height: 120px; resize: none"></textarea>
                      </div>
                  </div>
                  <div class="form-row">
                      <div class="form-item">
                          <input type="submit" class="button big black grid_1" value="Cevapla">
                      </div>
                  </div>
                  </form>
              </div>
          </div>
      <?php
            }
      } else {
          echo '<script>location="?";</script>';
      }
      }
      ?>

  </div>

<div class="footer">
  <p>Coded by <?php echo $_SERVER['HTTP_HOST']; ?></p>
</div>
<script>
    $(function() {
        $("#tabs").tabs();
        $('#selcoTablo').dataTable( {
            "bJQueryUI": true,
            "sPaginationType": "full_numbers"
        });
    });
</script>
<script src="js/script.js?v=<?php echo time(); ?>"></script>

</body>


</html>
<?php } else {
    header("Location: login.php");
} ?>